/*
 * board.h
 
  This file is part of Foobar.

  Foobar is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  Foobar is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
 
 * Created: 12/13/2013 2:16:41 AM
 *  Author: Tim
 */ 


#ifndef BOARD_H_
#define BOARD_H_

#include <avr/io.h>

#ifdef __IFAS_AIS_VCN__

#define dbLedPinMsk				0x04

#define XBee_PORT_CTS			PORTA
#define XBee_PORT_RTS			PORTA
#define XBee_PORT_SLEEP			PORTA
#define XBee_PORT_RESET			PORTA
#define XBee_PORT_RSSI			PORTA


#define XBee_CTS_PINMSK			0x04
#define XBee_RTS_PINMSK			0x10
#define XBee_SLEEP_PINMSK		0x08
#define XBee_RESET_PINMSK		0x02
#define XBee_RSSI_PINMSK		0x01

#define XBee_USART				USARTE0
#define XBee_PORT				PORTE	//keep in mind this is just the usart port. use signal specific ports to control signals

#define relay_PORT				PORTD

#define relay0_pinMsk			0x10
#define relay1_pinMsk			0x08

#define USB_PORT				PORTD
#define USB_USART				USARTD1

#define flowMeter_PORT			PORTE
#define flowMeter_PinMsk		0x01

#define flowMeterEnable()		(PORTE.PIN0CTRL = PORT_OPC_PULLUP_gc)
#define flowMeterDisable()		(PORTE.PIN0CTRL = PORT_OPC_TOTEM_gc)

#define BAT_REF_PORT			PORTB
#define BAT_REF_Enable_pinMsk	0x04

static inline flowMeterInit()
{
	//ensure the pin is set to input
	flowMeter_PORT.DIRCLR = flowMeter_PinMsk;
	
	//configure the pin interrupt sense to falling edge
	flowMeter_PORT.PIN0CTRL = PORT_ISC_FALLING_gc;
	
	//configure the pull-up resistor
	flowMeterEnable();
	
	//configure flow meter interrupt msk
	flowMeter_PORT.INT0MASK = flowMeter_PinMsk;
	
	//enable the interrupt
	flowMeter_PORT.INTCTRL = PORT_INT0LVL_HI_gc;
}
#else

#endif

#define dbLedInit() (PORTD.DIRSET = dbLedPinMsk)
#define dbLedOn()	(PORTD.OUTCLR = dbLedPinMsk)
#define dbLedInit()	(PORTD.OUTSET = dbLedPinMsk)

#endif /* BOARD_H_ */